package com.answer.controller;


import com.answer.model.dto.UserAnswer.UserAnswerAddDTO;
import com.answer.model.dto.UserAnswer.UserAnswerQueryDTO;
import com.answer.model.dto.UserAnswer.UserAnswerUpdateDTO;
import com.answer.model.dto.app.AppAddDTO;
import com.answer.model.dto.app.AppQueryDTO;
import com.answer.model.dto.app.AppUpdateDTO;
import com.answer.model.entity.UserAnswer;
import com.answer.model.reslut.Result;
import com.answer.model.reslut.ResultPage;
import com.answer.model.vo.AppVo;
import com.answer.model.vo.UserAnswerVo;
import com.answer.service.AppService;
import com.answer.service.UserAnswerService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/user/answer")
public class UserAnswerController {

    @Resource
    private UserAnswerService userAnswerService;



    //查询列表
    @PostMapping("/query/all")
    public Result queryAll(@RequestBody UserAnswerQueryDTO userAnswerQueryDTO){
        ResultPage<UserAnswerVo> userAnswerVoResultPage = userAnswerService.queryAll(userAnswerQueryDTO);
        return Result.success(userAnswerVoResultPage);
    }


    //根据id查询
    @GetMapping("/query/one/{id}")
    public Result queryOneById(@PathVariable Long id){
        UserAnswerVo userAnswerVo = userAnswerService.queryOneById(id);
        return Result.success(userAnswerVo);
    }


    //新增
    @PostMapping("/register")
    public Result register(@RequestBody UserAnswerAddDTO userAnswerAddDTO){
        UserAnswer res = userAnswerService.addUserAnswer(userAnswerAddDTO);
        return res!=null? Result.success(res.getId()):Result.faile("失败");
    }

    //修改
    @PostMapping("/update")
    public Result update(@RequestBody UserAnswerUpdateDTO userAnswerUpdateDTO){
        Boolean res = userAnswerService.updateUserAnswer(userAnswerUpdateDTO);
        return res? Result.success("修改成功"):Result.faile("修改失败");
    }

    //删除
    @PostMapping("/delete")
    public Result delete(Long id){
        Boolean res = userAnswerService.removeById(id);
        return res? Result.success("删除成功"):Result.faile("删除失败");
    }
}
